package com.itheima.jobs;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.service.OrderSettingService;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Component
public class ClearOrderSettingsJob {

    @Reference
    OrderSettingService orderSettingService;

    public void clearOrderSettings() {
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.YEAR,-1);
        calendar.add(Calendar.MONTH,+1);
        Date time = calendar.getTime();
        String format = new SimpleDateFormat("yyyy-MM-dd").format(time);
        orderSettingService.clearOrderSettingsByDate(format);
    }
}
